<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductReviewsTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('product_reviews', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('用户ID');
            $table->unsignedBigInteger('product_id')->comment('商品ID');
            $table->unsignedBigInteger('order_id')->comment('订单ID');
            // 评价内容
            $table->unsignedTinyInteger('rating')->comment('评分 1-5 星');
            $table->text('content')->comment('评价正文');

            $table->json('images')->nullable()->comment('评价图片 ["url1", "url2"]');
            $table->json('videos')->nullable()->comment('评价视频 ["url1", "url2"]');

            $table->tinyInteger('status')->comment('1-显示,2-屏蔽');

            // 互动数据
            $table->unsignedInteger('like_count')->default(0)->comment('点赞数');
            $table->boolean('is_anonymous')->default(false)->comment('是否匿名');

            // 商家回复
            $table->text('reply_content')->nullable()->comment('商家回复内容');
            $table->timestamp('replied_at')->nullable()->comment('回复时间');

            // 审核信息
            $table->foreignId('auditor_id')->nullable()->constrained('admins')->comment('审核人ID');
            $table->timestamp('audited_at')->nullable()->comment('审核时间');

            $table->index(['product_id', 'status'], 'product_status_index');
            $table->index(['user_id', 'created_at'], 'user_review_time_index');
            $table->timestamps();
        });
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `product_reviews` comment '商品用户评价'");
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('product_reviews');
    }
}
